package java_0500_collection;

import java.util.*;

public class HashSet01 {
    public static void main(String[] args) {
        Set set = new HashSet();
        //两个Tom都在常量池中，是同一个对象
        set.add("tom");
        set.add("tom");

        //两个Dog是不同的对象
        Dog dog = new Dog("tom");
        Dog dog2 = new Dog("tom");
        set.add(dog);
        set.add(dog2);

        //两个dog的name指向常量池中的同一个String“Tom”
        set.add(dog.getName());
        set.add(dog2.getName());

        //
        set.add("hello");
        set.add("hello");
        System.out.println(set);


        /**
         * 输出结果：[tom, java_0500_collection.Dog@4eec7777, java_0500_collection.Dog@3b07d329]
         */


    }
}

class Dog {
    private String name;

    public Dog(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}